package com.magic.uschat;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import com.lidroid.xutils.ViewUtils;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;


@SuppressLint("NewApi")
public class BaseActivity extends FragmentActivity{
	
	private Toast toast=null;
	
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		ViewUtils.inject(this);
		initView();
		
	}
	@Override
	protected void onStart() {
		super.onStart();
		EventBus.getDefault().register(this);
	}
	
	@Override
	protected void onStop() {
		EventBus.getDefault().unregister(this);
		super.onStop();
	}
	protected void initView(){};
	
	public void startActivity(Class<? extends Activity> target,Bundle bundle,boolean finish){
		Intent intent = new Intent();
		intent.setClass(this, target);
		if (bundle!=null) {
			intent.putExtra(getPackageName(), bundle);
		}
		startActivity(intent);
		if (finish) {
			finish();
		}
	}
	
	public void toast(String str){
		if (toast==null) {
			toast = Toast.makeText(this,null, Toast.LENGTH_LONG);
		}
		toast.setText(str);
		toast.show();
	}
	
	 @Subscribe
	 public void onEvent(Boolean empty){

	 }
	
	public Bundle getBundle() {
        if (getIntent() != null && getIntent().hasExtra(getPackageName()))
            return getIntent().getBundleExtra(getPackageName());
        else
            return null;
    }
	
}
